<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>提现</title>
	<%@ include file="../common/common.jsp"%>
	<link rel="stylesheet" type="text/css" href="${ctx}/page/lib/other/css/main.css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/page/lib/tinyalert/css/zepto.alert.css">
	<script type="text/javascript" src="${ctx}/page/lib/tinyalert/js/zepto.alert.js"></script>
</head>
<body>
<div class="line padding border-bottom">
	<div class="xs5 text-center">贝币余额：</div>
	<div class="xs7 text-big text-red"><fmt:formatNumber type="number" value="${jinBiBalance}" pattern="0.0000" maxFractionDigits="4"/></div>
</div>
<div class="line padding border-bottom">
	<div class="xs5 text-center">提现金额：</div>
	<div class="xs7"><span class="text-big text-green"><fmt:formatNumber type="number" value="${money}" pattern="0.00" maxFractionDigits="2"/></span>&nbsp;元</div>
</div>
<div class="line padding border-bottom">
	<div class="xs5 text-center">手续费(${rate})：</div>
	<div class="xs7"><span class="text-big text-green"><fmt:formatNumber type="number" value="${transferFee}" pattern="0.00" maxFractionDigits="2"/></span>&nbsp;元</div>
</div>
<div class="line padding border-bottom">
	<div class="xs5 text-center">实际到账：</div>
	<div class="xs7"><span class="text-big text-green"><fmt:formatNumber type="number" value="${actualCashAmount}" pattern="0.00" maxFractionDigits="2"/></span>&nbsp;元</div>
</div>
<div class="line padding">
	<div><input type="text" class="input" id="realName" name="realName"  placeholder="真实姓名" /></input></div>
</div>
<div class="line padding">
	<div><input type="text" class="input" id="aliAccount" name="aliAccount"  placeholder="支付宝帐号" /></input></div>
</div>
<div class="line padding">
	<div><input type="text" class="input" id="contact" name="contact"  placeholder="联系方式(微信、QQ或手机号)" /></input></div>
</div>
<div class=" padding-big">
	<p class="text-red">说明：</p>
	<span class="text-red text-small">
	1、提现金额需要是100的整数倍；
	<br>
	2、提现需要扣去${rate}的手续费。
	</span>
</div>

<div class="margin">
	<button id="sure" class="button bg-green button-big button-block">确认提现</button>
</div>

<script type="text/javascript">
	$(document).ready(function(){
		$("#sure").on("click",function(event){
			var money = "${money}";
			if(parseInt(money)<100){
			    $.dialog({
			        content : '贝币余额不足!',
			        title: "alert",
			        time : 2000
			    });
			}else{
				var realName = $("#realName").val();
				if(empty(realName)){
					 $.dialog({
						content : '请输入您的真实姓名!',
						title: "alert",
						time : 2000
					});
					 return;
				}
				
				var aliAccount = $("#aliAccount").val();
				if(empty(aliAccount)){
					 $.dialog({
						content : '请输入您的支付宝帐号!',
						title: "alert",
						time : 2000
					});
					 return;
				}
				
				var contact = $("#contact").val();
				if(empty(contact)){
					 $.dialog({
						content : '请输入您的联系方式!',
						title: "alert",
						time : 2000
					});
					 return;
				}
				
				sureCash(realName, aliAccount, contact);
			}
		});
	});
	var flag = true;
	function sureCash(realName, aliAccount, contact){
		if(flag){
			flag = false;
			var dialog = $.dialog({
		        content : '提现确认中,请稍后...'
		    });
			$.ajax({
				type : 'POST',
				url : ctx + '/page/cashApply.do',
				data : {
					realName:realName,
					aliAccount:aliAccount,
					contact:contact
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					dialog.close();
					if (data.code == "ok") {
						flag = true;
						var cashNo = data.object.cashNo;
						window.location.href=mServerUrl+"/page/cashSuccessPage.htm?cashNo="+cashNo+"&time="+((new Date()).getTime());
					} else {
						flag = true;
					    $.dialog({
					        content : data.msg,
					        title: "alert",
					        time : 2000
					    });
					}
				},
				error : function(xhr, type) {
					flag = true;
					dialog.close();
				    $.dialog({
				        content : '提交失败!',
				        title: "alert",
				        time : 2000
				    });
				}
			});
		}

	}

</script>
</body>
</html>